<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>9.9专区</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <style media="screen">
        .wrap {
            width: 100%;
            height: 100%;
            position: relative;
        }

        .index_bg {
            width: 100%;
            height: 100px;
            position: relative;
            z-index: 0;
            overflow: hidden;
        }

        .index_bg::after {
            content: '';
            width: 120%;
            height: 100px;
            position: absolute;
            left: -10%;
            top: 0;
            border-radius: 0 0 50% 50%;
            background: linear-gradient(266deg, #7D0DFC, #D116FD);
        }

        .content {
            width: 100%;
            position: absolute;
            padding: 0 15px;
            top: 0px;
        }

        .content ul {
            width: 100%;
            overflow: hidden;
        }

        .content ul li {
            width: 49%;
            background-color: #fff;
            padding: 5px;
            float: left;
            margin-left: 2%;
            margin-top: 10px;
            box-sizing: border-box;
            overflow: hidden;
            min-height: 245px;
        }

        .content ul li:nth-child(2n+1) {
            margin-left: 0;
        }

        .content ul li>.goods_picture {
            width: 100%;
            height: 155px;
        }

        .content ul li>.goods_picture img {
            display: block;
            width: 100%;
            height: 100%;
        }

        .content ul li>.intro {
            width: 100%;
            font-size: 14px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #333333;
        }

        .content ul li>.intro span {
            display: inline-block;
            width: 25px;
            height: 12px;
            float: left;
            margin-top: 2px;
        }

        .content ul li>.intro span img {
            display: block;
            width: 100%;
            height: 100%;
        }

        .content ul li>.price {
            width: 100%;
            overflow: hidden;
            display: flex;
            justify-content: space-between;
            margin-top: 8px;
        }

        .content ul li>.price .price_item {
            display: flex;
            width: auto;
        }

        .content ul li>.price .price_item:last-child {
            height: 15px;
            font-size: 14px;
            font-family: PingFang SC;
            font-weight: 400;
            color: #999999;
            line-height: 15px;
        }

        .content ul li>.price .price_item span:nth-child(1) {
            width: auto;
            height: 15px;
            font-size: 10px;
            font-family: PingFang SC;
            font-weight: 400;
            color: #999999;
            line-height: 17px;
        }

        .content ul li>.price .price_item span:nth-child(2) {
            width: auto;
            height: 15px;
            font-size: 10px;
            font-family: PingFang SC;
            font-weight: 400;
            color: #FF4242;
            line-height: 17px;
        }

        .content ul li>.price .price_item span:nth-child(3) {
            width: auto;
            height: 15px;
            font-size: 14px;
            font-family: PingFang SC;
            font-weight: 400;
            color: #FF4242;
            line-height: 15px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="wrap">
            <div class="index_bg"></div>
            <div class="content">
                <ul>
                    <li v-for='item in dataList' @click='openGoodsDtailsPage(item.goodsId)'>
                        <div class="goods_picture"><img :src="item.mainPic" alt="" v-cache-src="item.mainPic"></div>
                        <div class="intro">
                            <span class="icon" v-if='item.shopType==1'><img src="../../image/tm.png" alt=""></span>
                            <span class="icon" v-else><img src="../../image/tb_search.png" alt=""></span>
                            <!-- <span class="icon"><img src="" alt=""></span> -->
                            {{item.dtitle}}</div>
                        <div class="price">
                            <div class="price_item"><span>券后</span><span>￥</span><span>{{item.actualPrice}}</span></div>
                            <div class="price_item">已售{{item.monthSales}}</div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/vue.js"></script>
<script type="text/javascript" src="../../script/cling.js"></script>
<script type="text/javascript">
    /**
     * [注册一个全局自定义指令 `V-   cache-src`]
     * @param  {[type]} el      [需要图片缓存的元素]
     * @param  {[type]} binding [服务器图片对象数据]
     * @return {[type]}         [服务器图片地址]
     */
    Vue.directive('cache-src', function(el, binding) {
        if (binding) {
            setTimeout(function() {
                api.imageCache({
                    url: binding.value,
                    thumbnail: false
                }, function(ret, err) {
                    if (ret && ret.status) {
                        el.setAttribute("src", ret.url);
                    }
                });
            }, 100);
        }
    });
    apiready = function() {
        vm.init(vm.nineCid)
        vm.initRefresh();
        vm.bottomLoad();
    }
    var vm = new Vue({
        el: '#app',
        data: {
            nineCid: -1,
            dataList: []
        },
        methods: {
            clearData: function() {
                vm.dataList = [];
            },
            init: function(nineCid, isClick) {
                console.log(nineCid);
                vm.nineCid = nineCid;
                if (isClick) {
                    vm.pageId += 1;
                } else { // 下拉刷新 或者 初次加载
                    vm.pageId = 0;
                }
                cl.openLoading();
                api.ajax({
                    url: cl.apiServer + 'tb/getNineGoods',
                    method: 'post',
                    headers: {
                        'Content-Type': 'application/json;charset=utf-8',
                        token:cl.userToken
                    },
                    data: {
                        body: {
                            nineCid: nineCid,
                            pageId: vm.pageId,
                            pageSize: 20,
                            version:cl.deviceInfo().appVersion,
                            mobileInfo:cl.systemType()
                        }
                    }
                }, function(ret, err) {
                    console.log(JSON.stringify(ret))
                    if (ret) {
                        if (ret.code == 0) {
                            cl.closeLoading();
                            if (ret.data.totalNum > 0) {

                                if (ret.data.t.length >= 10) {
                                    vm.no_more = false;
                                } else if (ret.data.t.length == 0) {
                                    vm.no_more = true;
                                }
                                vm.dataList = vm.dataList.concat(ret.data.t);
                            } else {
                                // vm.isEnptyDataFigure = true;
                                // vm.no_more = false;
                                vm.dataList = [];
                            }
                        }
                    }
                })
            },
            //下拉刷新
            initRefresh: function() {
                cl.openRefresh(function() {
                    vm.init(vm.nineCid, false);
                })
            },
            //上拉加载
            bottomLoad: function() {
                cl.scrollBottom(function() {
                    vm.init(vm.nineCid, true);
                })
            },
            openGoodsDtailsPage: function(id) {
                cl.openWin({
                    name: 'goods_deatils',
                    pageParam: {
                        id: id
                    }
                })
            }
        }
    });
</script>

</html>
